﻿'Imports System.Runtime.Serialization

<Serializable()> _
Public Class clsNotification
	Inherits clsBaseClass

	Private keys As clsNotificationKeys
	Private soundFile As clsNotificationSound
	Private imageFile As clsNotificationImage
	Private notifyIcon As clsNotificationBalloon

	Private booPrevResult As Boolean

	Public Property KeysSettings() As clsNotificationKeys
		Get
			Return keys
		End Get
		Set(ByVal value As clsNotificationKeys)
			keys = value
		End Set
	End Property

	Public Property SoundFileSettings() As clsNotificationSound
		Get
			Return soundFile
		End Get
		Set(ByVal value As clsNotificationSound)
			soundFile = value
		End Set
	End Property

	Public Property ImageFileSettings() As clsNotificationImage
		Get
			Return imageFile
		End Get
		Set(ByVal value As clsNotificationImage)
			imageFile = value
		End Set
	End Property

	Public Property NotifyIconSettings() As clsNotificationBalloon
		Get
			Return notifyIcon
		End Get
		Set(ByVal value As clsNotificationBalloon)
			notifyIcon = value
		End Set
	End Property

	Public Sub New()
		Init()
	End Sub

	Public Sub New(ByVal strName As String)
		MyBase.New(strName)
		Init()
	End Sub

	Private Sub Init()
		keys = New clsNotificationKeys
		soundFile = New clsNotificationSound
		imageFile = New clsNotificationImage
		notifyIcon = New clsNotificationBalloon
	End Sub

	Public Function Notify() As Boolean
		Dim result As Boolean = KeysSettings.GetResult()
		If result = booPrevResult Then Return False

		booPrevResult = result
		If result = False Then Return False

		If Me.SoundFileSettings.Enabled Then SoundFileSettings.PlaySound()
		If Me.ImageFileSettings.Enabled Then ImageFileSettings.ShowImage(True)
		If Me.NotifyIconSettings.Enabled Then NotifyIconSettings.ShowBalloonTip()
		Return True
	End Function

	Public Overrides Sub Dispose()
		If KeysSettings IsNot Nothing Then
			KeysSettings.Dispose()
			keys = Nothing
		End If
		If SoundFileSettings IsNot Nothing Then
			SoundFileSettings.Dispose()
			soundFile = Nothing
		End If
		If ImageFileSettings IsNot Nothing Then
			ImageFileSettings.Dispose()
			imageFile = Nothing
		End If
		If NotifyIconSettings IsNot Nothing Then
			NotifyIconSettings.Dispose()
			notifyIcon = Nothing
		End If
		MyBase.Dispose()
	End Sub

	Protected Overrides Sub Finalize()
		Dispose()
		MyBase.Finalize()
	End Sub

	Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
		MyBase.GetObjectData(info, context)
		info.AddValue("Keys", KeysSettings)
		info.AddValue("SoundFile", SoundFileSettings)
		info.AddValue("ImageFile", ImageFileSettings)
		info.AddValue("NotifyIcon", NotifyIconSettings)
	End Sub
End Class
